<?php
/*
 * Encapsulation de la génération de fichiers PDF
 */
require_once(realpath(dirname(__FILE__)) . "/../lib/html2pdf/html2pdf.class.php");

class Pdf {

	// Valeurs par défaut
	const SENS = 'P'; // Orientation: P=portrait, L=landscape
	const FORMAT = 'A4'; // A5, etc.

	const LANG = 'fr'; // en, it, etc.

	const UNICODE = true;
	const ENCODING = 'UTF-8';
	const MARGIN = 0;

	private static $instance = false;

	private function __construct() {
	}

	public static function instance() {
		if (! $instance) self::$instance = new Pdf();

		return self::$instance;
	}

	public function generer(
			$html,
			$nom_fichier = '', $dest = 'I',
			$sens = self::SENS, $format = self::FORMAT, $margin = array(self::MARGIN, self::MARGIN, self::MARGIN, self::MARGIN)) {

	    try {

	        $html2pdf = new HTML2PDF($sens, $format, self::LANG, self::UNICODE, self::ENCODING, $margin);

	        $html2pdf->pdf->SetDisplayMode('real');

	        $html2pdf->writeHTML($html);

	        $html2pdf->Output($nom_fichier, $dest);
	    } catch(Exception $e) {
	        die("Echec de création du document PDF: $e");
	    }
	}
}
?>